home *** CD-ROM | disk | FTP | other *** search
/ Software Vault: The Gold Collection / Software Vault - The Gold Collection (American Databankers) (1993).ISO / cdr46 / parapass.zip / PARAPASS.8 next >
Text File  |  1993-05-03  |  18KB  |  387 lines

  1. ; PROGRAM : parapass
  2. ;
  3. ; VERSION : 0.0 (BETA TEST)  10/20/87
  4. ;
  5. ; INVOCATION : parapass <program name> </q>
  6. ;              the /q option is quiet option, it won't prompt for
  7. ;              parameters but will wait to read them
  8. ;
  9. ; AUTHOR : Rusty Baldwin
  10. ;          4783 W. 133rd St. #12
  11. ;          Hawthorne, CA  90250
  12. ;
  13. ; LANGUAGE : This program was developed with the A86 assembly language
  14. ;            if you want to assemble using MASM your on your own.
  15. ;            To assemble using A86 type : A86 PARAPASS.ASM
  16. ;
  17. ;            A86 can be obtained from:    Eric Isaacson
  18. ;                                         416 E. University
  19. ;                                         Bloomington, IN  47401
  20. ;                                         (812)339-1811
  21. ;
  22. ;
  23. ; DESCRIPTION : This program allows the interactive specification of
  24. ;               command line parameters. Microsoft EDLIN editor for
  25. ;               instance requires that the file to be edited be specified
  26. ;               on the command line (example: edlin myfile.doc). In a
  27. ;               operating environment such as DESQview this may not be
  28. ;               convenient however since parameters which are passed in
  29. ;               environments such as DESQview are static (i.e. you must
  30. ;               be content to edit myfile.doc constantly). This program
  31. ;               was developed to get around that problem. When you run
  32. ;               this program it will prompt you for the file to execute
  33. ;               (which must have a fully qualified path name) and the
  34. ;               parameters to pass to that program. It then runs the
  35. ;               program and 'fools' the program into thinking the para-
  36. ;               meters were passed on the command line.
  37. ;
  38. ;
  39. ; Miscellaneous Equates
  40. ;
  41. space          equ       20h            ; space
  42. cr             equ       0dh            ; carriage return
  43.  
  44. main:          call      init           ; get switches etc. on command line
  45.                test      b[status],80h  ; is quiet bit set?
  46.                jnz       >l1            ; yes
  47.                mov       dx,begin_msg   ; no, output program header
  48.                mov       ah,9h
  49.                int       21h
  50. l1:            mov       bx,[2ch]       ; specify environment block address
  51.                mov       [par_blk],bx   ; pass the environment we got.
  52.                mov       [p1],ds        ; THIS IS KLUDGEY SO I WANT TO
  53.                mov       [p2],ds        ; DO THIS BETTER LATER
  54.                mov       [p3],ds
  55. again:         mov       ch,0           ; clear ch
  56.                mov       cl,[80h]       ; get length of command tail
  57.                mov       al,[prg_add]   ; see if we have a program name
  58.                cmp       al,0
  59.                jne       >l1            ; yes we do
  60.  
  61. getname:       mov       dx,name_msg    ; nope, get program name
  62.                mov       ah,9h          ; this will send prompt even
  63.                int       21h            ; if quiet bit is set.
  64.                mov       b[80h],7fh     ; allow 128 bytes length
  65.                mov       dx,80h         ; get program name
  66.                mov       ah,0ah
  67.                int       21h
  68.                mov       ah,[81h]       ; get length of read
  69.                inc       ah             ; increase it by one
  70.                mov       [80h],ah       ; with this section we are
  71.                mov       b[81h],space   ; simulating, getting the program
  72.                                         ; name on the command line
  73.                call      init           ; call init again
  74.                jmp       again          ; try it again
  75.  
  76. l1:            call      valid          ; check validity of filename
  77.                cmp       al,0eh         ; invalid name? (0eh invalid
  78.                jne       >l2            ; file name error code)
  79.                jmp       alt            ; yes, display error message
  80.                                         ; use alternate entry point
  81. l2:            mov       si,[prg_add]   ; source pointer to name of program to run
  82.                and       si,0ffh        ; make sure msb is zero
  83.                mov       di,prg_nam     ; destination pointer
  84. l3:            mov       al,[si]        ; get a byte
  85.                mov       [di],al        ; put it in destination
  86.                inc       si             ; take care of pointers and such
  87.                inc       di
  88.                loop      l3             ; go get some more
  89.                mov       b[si],' '      ; put ' : $' at end of command tail for later use
  90.                inc       si             ; so we can output to user
  91.                mov       b[si],':'
  92.                inc       si
  93.                mov       b[si],'$'
  94.                test      b[status],80h  ; is quiet bit set?
  95.                jnz       >l1            ; yes
  96.                mov       dx,crlf        ; output crlf
  97.                mov       ah,9h
  98.                int       21h
  99.                mov       dx,prompt      ; prompt for parameters
  100.                mov       ah,9h          ; output it
  101.                int       21h
  102.                mov       dl,[prg_add]   ; output program name
  103.                mov       dh,0
  104.                int       21h
  105.                mov       dx,crlf        ; output crlf
  106.                mov       ah,9h
  107.                int       21h
  108. l1:            mov       dx,cmd_line-1  ; get cmd_line
  109.                mov       ah,0ah
  110.                int       21h
  111.                mov       dx,crlf        ; output crlf
  112.                mov       ah,9h
  113.                int       21h
  114.                mov       ah,29h         ; put cmd_line in FCB #1
  115.                mov       al,01          ; in case program looks there
  116.                mov       si,offset cmd_line+1
  117.                mov       di,ds
  118.                mov       es,di
  119.                mov       di,offset fcb1
  120.                int       21h
  121.                mov       [stk_seg],ss   ; save stack
  122.                mov       [stk_off],sp
  123.                mov       ah,25h         ; intercept any <CNTRL> C
  124.                mov       al,23h         ; so we can ingore it
  125.                mov       dx,int_ret
  126.                int       21h            ; ds should already be correct
  127.                mov       ah,4ah         ; release memory for EXEC'd program
  128.                mov       bx,eop-main    ; eop-main = program length in bytes
  129.                shr       bx,4           ; divide bx by 16 for paragraph length
  130.                add       bx,11h         ; add enough to take care of PSP
  131.                int       21h            ; release memory
  132.                mov       dx,prg_nam     ; set up to EXEC program
  133.                mov       bx,par_blk
  134.                mov       al,0
  135.                mov       ah,4bh
  136.                int       21h            ; EXEC program
  137.                mov       ss,[stk_seg]   ; restore stack
  138.                mov       sp,[stk_off]
  139.                jc        alt            ; if error print message
  140.                jmp       good_exit      ; if no error were done
  141.  
  142. int_ret:       iret                     ; dummy interrupt handler
  143.  
  144. alt:           mov       bl,al          ; convert error number to ASCII
  145.                cmp       bl,0ah
  146.                jg        >l1
  147.                add       bl,30h         ; convert to ASCII 1-9
  148.                mov       [error],bl
  149.                jmp       >l2
  150. l1:            add       bl,37h         ; convert to ASCII A-Z
  151.                mov       [error],bl     ; put error number in head_msg
  152. l2:            mov       dx,head_msg    ; output header
  153.                push      ax             ; save ax
  154.                mov       ah,9h
  155.                int       21h
  156.                pop       ax             ; restore it
  157.                cmp       al,1h          ; oh no an error,find out which one
  158.                je        err1           ; err1=function invalid
  159.                cmp       al,2h
  160.                je        err2           ; err2=file not found,path invalid
  161.                cmp       al,5h
  162.                je        err5           ; err5=access denied
  163.                cmp       al,8h
  164.                je        err8           ; err8=not enough memory
  165.                cmp       al,0ah
  166.                je        erra           ; erra=environment invalid
  167.                cmp       al,0bh
  168.                je        errb           ; errb=format invalid
  169.                cmp       al,0eh         ; erre=invalid filename
  170.                je        erre           ; LOCAL ERROR NOT SYSTEM
  171.                cmp       al,0fh         ; improper bundling of switches
  172.                je        errf           ; LOCAL ERROR NOT SYSTEM
  173.                mov       dx,erru_msg    ; unknown error OH MY!
  174.                mov       ah,9h
  175.                int       21h
  176.                jmp       bad_exit
  177.  
  178. err1:          mov       dx,err1_msg    ; output the various error messages
  179.                mov       ah,9h
  180.                int       21h
  181.                jmp       bad_exit
  182. err2:          mov       dx,err2_msg
  183.                mov       ah,9h
  184.                int       21h
  185.                jmp       bad_exit
  186. err5:          mov       dx,err5_msg
  187.                mov       ah,9h
  188.                int       21h
  189.                jmp       bad_exit
  190. err8:          mov       dx,err8_msg
  191.                mov       ah,9h
  192.                int       21h
  193.                jmp       bad_exit
  194. erra:          mov       dx,erra_msg
  195.                mov       ah,9h
  196.                int       21h
  197.                jmp       bad_exit
  198. errb:          mov       dx,errb_msg
  199.                mov       ah,9h
  200.                int       21h
  201.                jmp       bad_exit
  202. erre:          mov       dx,invalid_msg
  203.                mov       ah,9h
  204.                int       21h
  205.                jmp       bad_exit
  206. errf:          mov       dx,bundle_msg
  207.                mov       ah,9h
  208.                int       21h
  209.                jmp       bad_exit
  210.  
  211. bad_exit:      mov       ah,4ch         ; al should have error code
  212.                int       21h
  213.  
  214. good_exit:     mov       al,0           ; quit with return code 0
  215.                mov       ah,4ch
  216.                int       21h
  217.  
  218. init:          mov       bx,81h         ; look for switches starting at
  219. scan:          mov       al,[bx]        ; PSP address 81h
  220.                cmp       al,cr          ; if cr were done
  221.                jne       >l1
  222.                jmp       pname          ; done, so go look for program name
  223. l1:            cmp       al,space       ; if space skip it
  224.                je        >l2
  225.                cmp       al,'/'         ; if not switch keep looking
  226.                jne       >l2
  227.                inc       bx             ; it's a switch, which one?
  228.                mov       al,[bx+1]      ; before switch test make sure
  229.                cmp       al,space       ; next character is a space or /
  230.                                         ; or cr else the switches are not
  231.                                         ; bundled correctly
  232.                je        >l3
  233.                cmp       al,'/'
  234.                je        >l3
  235.                cmp       al,cr
  236.                je        >l3
  237.                mov       al,0fh         ; internal error code
  238.                jmp       alt            ; jmp to alternate error entry point
  239. l3:            mov       al,[bx]        ; HERE WE TEST FOR ALL SWITCHES
  240.                cmp       al,'q'         ; quiet mode?
  241.                jne       >l4
  242.                or        b[status],80h  ; set quiet bit
  243. l4:            cmp       al,'Q'
  244.                jne       >l2
  245.                or        b[status],80h  ; set quiet bit, END TEST FOR SWITCHES
  246. l2:            inc       bx             ; keep looking
  247.                jmp       scan
  248. pname:         mov       bx,80h         ; now look for program name
  249.                mov       cl,0h          ; initialize length to zero
  250. l1:            inc       bx
  251.                mov       al,[bx]
  252.                cmp       al,cr          ; if cr we're done
  253.                je        tini
  254.                cmp       al,space       ; if space skip it
  255.                je        l1
  256.                cmp       al,'/'         ; a switch skip it plus next char
  257.                jne       >l2
  258.                inc       bx             ; skip next char
  259.                jmp       l1
  260. l2:            mov       [prg_add],bl   ; it's a prog name, bump count
  261. l3:            inc       cl             ; save location and look for cr
  262.                inc       bx
  263.                mov       al,[bx]
  264.                cmp       al,cr
  265.                je        tini
  266.                cmp       al,space       ; it a space, we assume program
  267.                jne       l3             ; name is done
  268. tini:          mov       [80h],cl       ; save length of name
  269.                ret
  270.  
  271. valid:         mov       bl,[prg_add]   ; start looking for .com or .exe
  272.                and       bh,0           ; zero out bh
  273. l1:            mov       al,[bx]
  274.                cmp       al,cr          ; found cr ?
  275.                je        done           ; yup
  276.                cmp       al,'.'         ; looking for '.'
  277.                je        >l2
  278.                inc       bx
  279.                jmp       l1
  280. l2:            inc       bx             ; look at next char
  281.                mov       al,[bx]
  282.                cmp       al,'c'
  283.                je        >l3
  284.                cmp       al,'C'
  285.                je        >l3
  286.                cmp       al,'e'
  287.                je        >l4
  288.                cmp       al,'E'
  289.                je        >l4
  290.                mov       al,0eh         ; not valid, return with error
  291.                ret
  292.  
  293. done:          mov       al,0eh         ; didn't find .??? so invalid
  294.                ret
  295.  
  296. l3:            inc       bx             ; found 'c' look for 'o'
  297.                mov       al,[bx]
  298.                cmp       al,'o'
  299.                je        >l5
  300.                cmp       al,'O'
  301.                je        >l5
  302.                mov       al,0eh
  303.                ret                      ; no 'o' bad filename
  304. l5:            inc       bx
  305.                mov       al,[bx]
  306.                cmp       al,'m'
  307.                je        >l1
  308.                cmp       al,'M'
  309.                jne       >l2
  310. l1:            mov       al,0           ; valid filename try it
  311.                ret
  312. l2:            mov       al,0eh         ; bad file name
  313.                ret
  314. l4:            inc       bx             ; found 'e' look for 'x'
  315.                mov       al,[bx]
  316.                cmp       al,'x'
  317.                je        >l5
  318.                cmp       al,'X'
  319.                je        >l5
  320.                mov       al,0eh
  321.                ret                      ; no 'X' bad filename
  322. l5:            inc       bx
  323.                mov       al,[bx]
  324.                cmp       al,'e'
  325.                je        >l3
  326.                cmp       al,'E'
  327.                jne       l2
  328. l3:            mov       al,0           ; valid filename try it
  329.                ret
  330.  
  331. ;
  332. ; General Messages
  333. ;
  334.  
  335. prompt:        db        'Enter parameters to pass to $'
  336. crlf:          db        0dh,0ah,'$'
  337. name_msg:      db        0dh,0ah,'Enter filespec of program to execute '
  338.                db        '(COM or EXE extension required) :',0ah,0dh,'$'
  339. begin_msg:     db        0dh,0ah,'Parapass - the parameter '
  340.                db        'passing program - Version 0.0',0dh,0ah,'$'
  341.  
  342. ;
  343. ; Error Messages
  344. ;
  345.  
  346. head_msg:      db        0dh,0ah,'parapass : error '
  347. error:         db        0,' - $'
  348. err1_msg:      db        'Invalid function (notify author).',0dh,0ah,'$'
  349. err2_msg:      db        'File not found or path invalid.',0dh,0ah,'$'
  350. err5_msg:      db        'Access denied.',0dh,0ah,'$'
  351. err8_msg:      db        'Insufficient memory.',0dh,0ah,'$'
  352. erra_msg:      db        'Environment invalid (notify author).',0dh,0ah,'$'
  353. errb_msg:      db        'Format invalid (notify author).',0dh,0ah,'$'
  354. erru_msg:      db        'Unknown error (notify author).',0dh,0ah,'$'
  355. invalid_msg:   db        'Invalid program name, must be COM or EXE.'
  356.                db        0dh,0ah,'                     '
  357.                db        'See instructions for BAT file execution.'
  358.                db        0dh,0ah,'$'
  359. bundle_msg:    db        'Improper switch configuration.',0dh,0ah,'$'
  360. ;
  361. ; Data
  362. ;
  363. prg_add:       db        0              ; offset of program name within PSP
  364. prg_nam:       db        128 dup (0)    ; prg_nam buffer
  365.                db        7fh            ; max characters to read on cmd_line
  366. cmd_line:      db        128 dup (?)    ; command line buffer
  367. stk_seg:       dw        0              ; original SS contents
  368. stk_off:       dw        0              ; original SP contents
  369. status:        db        0              ; status byte : bit 7 set = quiet mode
  370. par_blk:       dw        0              ; segment address of
  371.                                         ; environment descriptor
  372.                dw        offset cmd_line; address of command line
  373. p1:            dw        0              ; to be passed to program
  374.                dw        offset fcb1    ; address of default FCB 1
  375. p2:            dw        0
  376.                dw        offset fcb2    ; address of default FCB 2
  377. p3:            dw        0
  378. fcb1:          db        0              ; file control block #1
  379.                db        11 dup ('?')
  380.                db        25 dup (0)
  381. fcb2:          db        0              ; file control block #2
  382.                db        11 dup (' ')
  383.                db        25 dup (0)
  384. eop:           db        0              ; end of program place holder
  385.                                         ; used for program size
  386.                                         ; calculation
  387.